package com.os.ch2.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @Author Matt
 * @Date 2022-01-11
 * @Desc:
 * @Version V1.0
 */
@Component
public class DemoPublisher {

    @Autowired
    ApplicationContext applicationContext;  //注入applicationcontext来发布事件

    public void publish(String msg){
        applicationContext.publishEvent(new DemoEvent(this, msg));  //使用publish方法来发布事件
    }

}
